#pragma once

VOID player_finalize(JSContext *cx, JSObject *obj);
INT player_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
INT player_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);

#define DEFFNC(f) INT f (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);

DEFFNC(player_getNext)

#undef DEFFNC

/**********************************************************

					Classes/Objects/Methods

 **********************************************************/

static JSClass player_class = {
    "playerunit",	JSCLASS_HAS_PRIVATE,
    JS_PropertyStub, JS_PropertyStub, player_getProperty, player_setProperty,
    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, player_finalize,
    NULL, NULL, 
};

enum player_tinyid {
	PLAYER_NAME = 0,
	PLAYER_GOLD,
	PLAYER_LUMBER,
	PLAYER_SUPPLYMAX,
	PLAYER_SUPPLY,
	PLAYER_SLOT,
	PLAYER_RACE,
	PLAYER_STARTX,
	PLAYER_STARTY,
};

enum me_tinyid {
	ME_PLAYERS = 100,
	ME_MAXPLAYERS,
	ME_MAPNAME,
};

static JSPropertySpec player_props[] = {
	{"name",		PLAYER_NAME,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"gold",		PLAYER_GOLD,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"lumber",		PLAYER_LUMBER,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"supply"	,	PLAYER_SUPPLY,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"maxsupply",	PLAYER_SUPPLYMAX,	JSPROP_ENUMERATE | JSPROP_READONLY},
	{"slot",		PLAYER_SLOT,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"race",		PLAYER_RACE,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"startx",		PLAYER_STARTX,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"starty",		PLAYER_STARTY,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{0},
};

static JSPropertySpec me_props[] = {
	{"name",		PLAYER_NAME,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"gold",		PLAYER_GOLD,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"lumber",		PLAYER_LUMBER,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"supply"	,	PLAYER_SUPPLY,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"maxsupply",	PLAYER_SUPPLYMAX,	JSPROP_ENUMERATE | JSPROP_READONLY},
	{"slot",		PLAYER_SLOT,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"race",		PLAYER_RACE,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"startx",		PLAYER_STARTX,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"starty",		PLAYER_STARTY,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"players",		ME_PLAYERS,			JSPROP_ENUMERATE | JSPROP_READONLY},
	{"maxplayers",	ME_MAXPLAYERS,		JSPROP_ENUMERATE | JSPROP_READONLY},
	{"mapname",		ME_MAPNAME,			JSPROP_ENUMERATE | JSPROP_READONLY},
	{0},
};
static JSFunctionSpec player_methods[] = {
	{"getNext",			player_getNext,		0},
	{0},
};

struct myPlayer
{
	DWORD _dwPrivateType;
	DWORD dwPlayerSlot;
	CHAR szName[64];
};
